<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>定位特殊应用_2</title>
</head>
<style>
    .container {
        width: 500px;
        height: 500px;
        background-color: gray;
        position: relative;
    }

    .box_1 {
        width: 200px;
        height: 200px;
        background-color: bisque;
        position: absolute;

        /*方法一：推荐使用*/
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);

        /*方法二：不推荐使用*/
        /*top: 0;*/
        /*right: 0;*/
        /*left: 0;*/
        /*bottom: 0;*/
        /*margin: auto;*/
    }
    span{
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
    }
</style>
<body>
<div class="container">
    <div class="box_1">
        <span>小盒子在父亲的盒子中水平垂直居中</span>
    </div>
</div>
</body>
</html>